/*
 * @Author: silence
 * @Date: 2023-08-18 14:25:17
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-09-27 17:07:05
 * @Description: 设备链接进度
 */
import 'package:ems_neutral_app/utils/color/ColorUtils.dart';
import 'package:flutter/material.dart';
import 'package:sil_base_widget_package/sil_base_widget_package.dart';

import '../Controller/DeviceNetworkingController.dart';

class DNNetProgressItem extends StatefulWidget {
  /// 进度线，默认显示
  final bool showProgressLine;

  /// 进度状态，默认准备状态
  final DNNetProgressItemState proState;

  /// 准备状态的图片地址
  final String? prepareImgPath;

  /// 失败状态的图片地址
  final String? failImgPath;

  /// title
  final String? title;
  const DNNetProgressItem(
      {this.title,
      this.showProgressLine = true,
      this.proState = DNNetProgressItemState.prepare,
      this.prepareImgPath,
      this.failImgPath,
      super.key});

  @override
  State<DNNetProgressItem> createState() => _DNNetProgressItemState();
}

class _DNNetProgressItemState extends State<DNNetProgressItem> {
  Color lineColor = ColorUtils.color_subtitle;

  @override
  Widget build(BuildContext context) {
    switch (widget.proState) {
      case DNNetProgressItemState.prepare:
        lineColor = ColorUtils.color_subtitle;
        break;
      case DNNetProgressItemState.progressing:
        lineColor = ColorUtils.color_theme;
        break;
      case DNNetProgressItemState.success:
        lineColor = ColorUtils.color_theme;
        break;
      case DNNetProgressItemState.fail:
        lineColor = ColorUtils.hexColor("#A20909");
        break;
    }
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        if (widget.showProgressLine) progerssLineWidget(),
        stateFlagWidget()
      ],
    );
  }

  /// 进度线
  progerssLineWidget() {
    return Container(
      width: 1.w,
      height: 52.w,
      color: lineColor,
      margin: EdgeInsets.only(left: 16.5.w),
    );
  }

  /// 状态标识
  stateFlagWidget() {
    Widget flagWidget = Container();

    switch (widget.proState) {
      case DNNetProgressItemState.prepare:
        flagWidget = SilImage(
          widget.prepareImgPath,
          width: 34.w,
          height: 34.w,
        );
        break;
      case DNNetProgressItemState.progressing:
        flagWidget = CircularProgressIndicator(
            color: ColorUtils.color_theme, strokeWidth: 2.0);

        break;
      case DNNetProgressItemState.success:
        flagWidget = SilImage(
          'imgs/device_net/device_net_pro_success.png',
          width: 34.w,
          height: 34.w,
        );
        break;
      case DNNetProgressItemState.fail:
        flagWidget = SilImage(
          widget.failImgPath ?? 'imgs/device_net/device_net_por_fail.png',
          width: 34.w,
          height: 34.w,
        );
        break;
    }

    return Row(
      children: [
        Container(
          width: 34.w,
          height: 34.w,
          child: flagWidget,
        ),
        Expanded(
            child: SilText(
          widget.title,
          fontSize: 15.sp,
          color: lineColor,
          maxLines: 0,
          margin: EdgeInsets.only(left: 25.w),
        )),
      ],
    );
  }
}
